package com.raylu.gmallbigscreen.controller;

import com.alibaba.fastjson.JSONObject;
import com.raylu.gmallbigscreen.service.ProductStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * Description:
 * <p>
 * Create by lucienoz on 2022/1/10.
 * Copyright © 2022 lucienoz. All rights reserved.
 */
@RestController
@RequestMapping("/api/sugar")
public class ProductStatsController {
    @Autowired
    private ProductStatsService productStatsService;

    @RequestMapping("/gmv")
    public String getGmv(@RequestParam(value = "date",defaultValue = "0")Integer date){


        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"data\": "+productStatsService.getGmv(date)+"\n" +
                "}";

    }

    @RequestMapping("/productstatsbytm")
    public String getProductStatsByTm(@RequestParam(value = "date",defaultValue = "0")Integer date,
                                          @RequestParam("limit")Integer limit){
        JSONObject productStatsByTm = productStatsService.getProductStatsByTm(date, limit);
        return productStatsByTm.toJSONString();
    }

}
